<template>
	<view class="all">
		<view class="top">
			<view class="head">
				<image class="top-image" :src="slist[0].listPhoto" mode="widthFix" />
				<view class="textInfo">
					<view class="text">
						添加到歌单
					</view>
					<view class="time">
						{{time}}
					</view>
				</view>
			</view>
			<view class="zhongjian">
				<text class="zi">推荐歌单({{slist.length}})</text>
			</view>
		</view>
		<view>
			<view class="itemInfo">
				<view class="songListItem">
					<view class="list1" @tap="getSongList(item.listId)" v-for="item in slist" :key="item.listId">
						<view class="list1Pho">
							<image :src="item.listPhoto" class="listItem"></image>
						</view>
						<view>
							<text class="listTex">{{item.listTittle}}</text>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view style="height: 60rpx;"></view>
	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex'
	export default {
		data() {
			return {
				slist: [],
				code: Number,
				time: "",
				songId:0
			};
		},
		computed: {
			...mapState('user', ['userInfo'])
		},
		methods: {

			timestampToTime(times) {
				let time = times[1]
				let mdy = times[0]
				mdy = mdy.split('/')
				let month = parseInt(mdy[0]);
				let day = parseInt(mdy[1]);
				let year = parseInt(mdy[2])
				return year + '-' + month + '-' + day + ' ' + time
			},
			async getListById(id) {
				const {
					data: res
				} = await uni.$http.get("/list/findListById?listId=" + id)
				console.log(res);
				if (res.code != 200) {
					uni.showToast({
						title: "获取信息失败",
						duration: 1000,
						position: 'center',
						icon: 'error'
					})
				}
				this.slist = res.data
				this.code = res.code
				let time = new Date()
				let nowTime = this.timestampToTime(time.toLocaleString('en-US', {
					hour12: false
				}).split(" "))
				this.time = nowTime
			},
			async getSongList(listId) {
				const {data:res} =  await uni.$http.get("/list/insertListSong",{
					listId:listId,
					songId:this.songId
				})
				if(res.code==200){
					uni.navigateBack()
					uni.showToast({
						duration:1000,
						icon:'success',
						title:res.data
					})
				}else{
					uni.showToast({
						duration:1000,
						icon:'error',
						title:res.msg
					})
				}
				
			}
		},
		onLoad(item) {
			this.songId = item.songId
			this.getListById(this.userInfo.userId)
		}
	}
</script>

<style lang="scss">
	.top {
		background-color: #FAACA8;
		background-image: linear-gradient(180deg, #FAACA8 0%, #DDD6F3 57%, #f0f0f0 96%);
	}

	.textInfo {
		margin-left: 35rpx;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		height: 130rpx;
	}

	.text {
		margin-left: 30rpx;
		font-family: 宋体;
		font-size: 50rpx;
		font-weight: bolder;
	}

	.time {
		color: #5c5c5c
	}

	.head {
		width: 100%;
		height: 340rpx;
		display: flex;
		margin-left: 80rpx;
		align-items: center;
	}

	.top-image {
		width: 250rpx;
		border-radius: 20rpx;
	}

	.head {
		height: 500rpx;
		height: 500rpx;

	}

	.zhongjian {
		padding: 10rpx 30rpx;
		border-top: 2rpx solid gray;
		border-bottom: 2rpx solid gray;

		.zi {
			font-size: 35rpx;
			font-weight: 600;
			margin: 20rpx 40rpx;
		}
	}

	.scroll-item {
		padding-top: 20rpx;
		display: flex;
		background-color: #f0f0f0;
		/* justify-content: space-around; */
	}

	.song-number {
		width: 80rpx;
		line-height: 100rpx;
		text-align: center;
		font-size: 45rpx;
		margin-left: 20rpx;
		font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
		color: rgba(100, 98, 98, 0.8);
	}

	.scroll-item .song-info {
		position: relative;
		flex: 1;
		max-width: 50%;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		margin-bottom: 3px;
	}

	.song-info .song-title {
		font-size: 36rpx;
		color: #111;
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
	}

	.song-info .song-desc {
		font-size: 28rpx;
		color: #5c5c5c;
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
	}


	.song-info .song-desc .bgimg {
		width: 60rpx;
		margin-right: 5rpx;
	}

	.s {
		position: absolute;
		right: 60rpx;
		margin-top: 10px;
	}

	.songListItem {
		display: flex;
		flex-flow: wrap;
		justify-content: space-around;
	}

	.listItem {
		width: 290rpx;
		height: 290rpx;
		border-radius: 15%;
		box-shadow: 10rpx 10rpx 10rpx rgba(0, 0, 0, .2);
	}

	.list1 {
		margin-top: 20rpx;
		display: inline-block;
		width: 290rpx;
	}

	.listTex {
		width: 100%;
		font-size: 30rpx;
		// word-wrap: break-word;
		// word-break: normal;
		display: -webkit-box;
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: pre-wrap;
		-webkit-line-clamp: 1;
		-webkit-box-orient: vertical;
		margin-top: 20rpx;
		font-weight: 550;
	}
</style>
